package com.example.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.pojo.AppVersion;
import com.example.pojo.PageData;
import com.example.pojo.ResultBean;
import com.example.service.IAppVersionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyj
 * @since 2023-02-13
 */
@RestController
@RequestMapping("/app-version")
public class AppVersionController {
    @Autowired
    private IAppVersionService appVersionService;

    @GetMapping("/list")
    @RequiresPermissions("system:default")
    public ResultBean list(PageData pageData,
                           @RequestParam Map map){
        Page page = new Page(pageData.getPageNum(),pageData.getPageSize());
        appVersionService.lambdaQuery()
                .like(!ObjectUtils.isEmpty(map.get("keyWord")), AppVersion::getAppExplain, map.get("keyWord"))
                .le(!ObjectUtils.isEmpty(map.get("endTime")),AppVersion::getUpdateDate,map.get("endTime"))
                .ge(!ObjectUtils.isEmpty(map.get("startTime")),AppVersion::getUpdateDate,map.get("startTime"))
                .page(page);
        return ResultBean.success(page);
    }

    @PostMapping("/saveOrUpdate")
//    @RequiresPermissions("dfsdfsfsdfsdfsdf")
    public ResultBean saveOrUpdate(@RequestBody AppVersion appVersion){
        System.out.println("新增或修改的数据：" + appVersion);
        boolean rs = appVersionService.saveOrUpdate(appVersion);
        return rs ? ResultBean.success() : ResultBean.error("操作失败");
    }

    @DeleteMapping("/delete/{id}")
    public ResultBean delete(@PathVariable("id") Long id){
        System.out.println("要删除的Id" + id);
        boolean rs = appVersionService.removeById(id);
        return rs ? ResultBean.success() : ResultBean.error("操作失败");
    }

}
